<!DOCTYPE html>
<html>
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>传智健康</title>
        <meta name="description" content="传智健康">
        <meta name="keywords" content="传智健康">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <!-- 引入样式 -->
        <link rel="stylesheet" href="../plugins/elementui/index.css">
        <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
        <link rel="stylesheet" href="../css/style.css">
    </head>
    <body class="hold-transition">
        <div id="app">
            <div class="content-header">
                <h1>预约管理<small>预约列表</small></h1>
                <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>预约管理</el-breadcrumb-item>
                    <el-breadcrumb-item>预约列表</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
            <div class="app-container">
                <div class="box">
                    <div class="filter-container">
                        <el-input placeholder="姓名/手机号" v-model="pagination.queryString" style="width: 200px;" class="filter-item"></el-input>
                        <el-button @click="findPage()" class="dalfBut">查询</el-button>
                        <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                        <el-button type="danger" class="butT" @click="handleDeleteAll()">批量取消</el-button>
                    </div>
                    <el-table size="small" @selection-change="selectcheckBox" current-row-key="id" :data="dataList" stripe highlight-current-row >
                        <el-table-column type="selection" prop="id"></el-table-column>
                        <el-table-column prop="orderDate" label="预约日期" align="center" value-format="yyyy-MM-dd"></el-table-column>
                        <el-table-column prop="member.fileNumber" label="档案号" align="center"></el-table-column>
                        <el-table-column prop="member.name" label="姓名" align="center"></el-table-column>
                        <el-table-column prop="member.phoneNumber" label="手机号" align="center"></el-table-column>
                        <el-table-column prop="orderType" label="预约类型" align="center"></el-table-column>
                        <el-table-column prop="orderStatus" label="预约状态" align="center"></el-table-column>
                        <el-table-column label="操作" align="center" width="240">
                            <template slot-scope="scope">
                                <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">确定预约</el-button>
                                <el-button size="mini" type="danger" @click="handleDelete(scope.row)">取消预约</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <div class="pagination-container">
                        <el-pagination
                            class="pagiantion"
                            @current-change="handleCurrentChange"
                            :current-page="pagination.currentPage"
                            :page-size="pagination.pageSize"
                            layout="total, prev, pager, next, jumper"
                            :total="pagination.total">
                        </el-pagination>
                    </div>
                    <!-- 新增标签弹层 -->
                    <div class="add-form">
                        <el-dialog title="新增预约" :visible.sync="dialogFormVisible">
                            <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right" label-width="100px">
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="预约日期" prop="orderDate">
                                            <el-date-picker
                                                    v-model="formData.orderDate"
                                                    type="date"
                                                    placeholder="选择日期"
                                                    format="yyyy 年 MM 月 dd 日"
                                                    value-format="yyyy-MM-dd">
                                            </el-date-picker>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="档案号" prop="fileNumber">
                                            <el-input v-model="formData.fileNumber"/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="姓名" prop="name">
                                            <el-input v-model="formData.name"/>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="手机号" prop="telephone">
                                            <el-input v-model="formData.telephone"/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="套餐列表">
                                            <el-select v-model="formData.setmealId" placeholder="请选择">
                                                <el-option
                                                        v-for="item in setmealList"
                                                        :key="item.id"
                                                        :label="item.name"
                                                        :value="item.id">
                                                </el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="预约状态" prop="orderStatus">
                                            <el-select v-model="formData.orderStatus">
                                                <el-option label="已到诊" value="已到诊"></el-option>
                                                <el-option label="未到诊" value="未到诊"></el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                            </el-form>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible = false">取消</el-button>
                                <el-button type="primary" @click="handleAdd()">确定</el-button>
                            </div>
                        </el-dialog>
                    </div>
                </div>
            </div>
        </div>
    </body>
    <!-- 引入组件库 -->
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <script>
        var vue = new Vue({
            el: '#app',
            data:{
                pagination: {//分页相关模型数据
					  currentPage: 1,//当前页码
					  pageSize:10,//每页显示的记录数
					  total:0,//总记录数
					  queryString:null//查询条件
				},
                ids:[],//复选框id
                checkBoxData:[],//复选框内容
                setmealList:{},//套餐列表
				dataList: [],//当前页要展示的分页列表数据
                formData: {},//表单数据
                dialogFormVisible: false,//增加表单是否可见
                rules: {//校验规则
                    telephone: [{ required: true, message: '手机号为必填项', trigger: 'blur' }],
                    name: [{ required: true, message: '姓名为必填项', trigger: 'blur' }]
                }
            },
            //钩子函数，VUE对象初始化完成后自动执行
            created() {
                this.findPage();//VUE对象初始化完成后调用分页查询方法，完成分页查询
            },
            methods: {
                //添加
                handleAdd () {
                    axios.post("/OrderSettingList/add.do",this.formData).then((res)=>{
                        if (res.data.flag){
                            this.$message({
                                type:'success',
                                message:res.data.message
                            });
                        } else{
                            this.$message.error(res.data.message);
                        }
                    }).finally(()=>{
                        this.dialogFormVisible=false;
                        this.findPage();
                    });
                },
                //分页查询
                findPage() {
                    //封装分页参数
                    var param = {
                        currentPage:this.pagination.currentPage,
                        pageSize:this.pagination.pageSize,
                        queryString:this.pagination.queryString
                    };
                    axios.post("/OrderSettingList/findPage.do",param).then((res)=>{
                        this.pagination.total=res.data.total;
                        this.dataList=res.data.rows;
                    });
                },
                // 重置表单
                resetForm() {
                    this.formData = {};//重置数据
                },
                // 弹出添加窗口
                handleCreate() {
                    //弹出新增窗口
                    this.dialogFormVisible = true;
                    this.resetForm();
                    axios.get("/setmeal/findAll.do").then((res)=>{
                        if (res.data.flag){
                            this.setmealList=res.data.data;
                        }else {
                            this.$message.error(res.data.message);
                        }
                    })
                },
                //切换页码
                handleCurrentChange(currentPage) {
                    //设置最新的页码
                    this.pagination.currentPage = currentPage;
                    //重新调用findPage方法进行分页查询
                    this.findPage();
                },

                showMessage(r){
                    if(r == 'Error: Request failed with status code 403'){
                        //权限不足
                        this.$message.error('无访问权限');
                        return;
                    }else{
                        this.$message.error('未知错误');
                        return;
                    }
                },
                //确定预约
                handleUpdate(row){

                    if (row.orderStatus=="已到诊"){
                        alert("已确定预约");
                    }else{
                        this.$confirm('是否确定客户已到诊?', '确定预约', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            type: 'warning'
                        }).then(() => {
                            axios.get("/OrderSettingList/update.do?id="+row.id).then((res)=>{
                                if (res.data.flag){
                                    this.$message({
                                        type: 'success',
                                        message: '确定预约成功!'
                                    });
                                } else{
                                    this.data.messagea("确定预约失败");
                                }
                            }).finally(()=>{
                                this.findPage();
                            });
                        }).catch(() => {
                            this.$message({
                                type: 'info',
                                message: '取消确定预约'
                            });
                        });
                    }

                },
                // 取消预约
                handleDelete(row) {
                    this.checkBoxData=[];
                    this.ids.push(row.id);
                    this.checkBoxData.push(row);
                    var f=true;
                    if (this.checkBoxData[0]['orderStatus']=="已到诊"){
                        f=false;
                        alert("该预约以到诊,无法取消");
                    }
                    if (f) {
                        if (this.ids!=[]&&this.ids.length>0){
                            this.$confirm('是否取消预约?', '取消预约', {
                                confirmButtonText: '确定',
                                cancelButtonText: '取消',
                                type: 'warning'
                            }).then(() => {
                                axios.post("/OrderSettingList/delete.do?ids="+this.ids,this.checkBoxData).then((res)=>{
                                    if (res.data.flag){
                                        this.$message({
                                            type:'success',
                                            message:'取消预约成功'
                                        })
                                    }
                                }).finally(()=>{
                                    this.findPage();
                                    this.ids=[];
                                    this.checkBoxData=[];
                                });
                            }).catch(() => {
                                this.$message({
                                    type: 'info',
                                    message: '放弃取消预约'
                                });
                            });
                        } else{
                            alert("请至少选择一条数据")
                        }

                    }

                },
                //批量取消
                handleDeleteAll(){
                    var f=true;
                    for (var i = 0 , len = this.checkBoxData ; i < len.length; i++) {
                        if (len[i]['orderStatus']=="已到诊"){
                            f=false;
                            alert("存在已到诊预约,请重新选择");
                            break;
                        }
                    }
                    if (f) {
                        if (this.ids!=[]&&this.ids.length>0){
                            this.$confirm('是否批量取消预约?', '批量取消预约', {
                                confirmButtonText: '确定',
                                cancelButtonText: '取消',
                                type: 'warning'
                            }).then(() => {
                                axios.post("/OrderSettingList/delete.do?ids="+this.ids,this.checkBoxData).then((res)=>{
                                    if (res.data.flag){
                                        this.$message({
                                            type:'success',
                                            message:'批量取消预约成功'
                                        })
                                    }
                                }).finally(()=>{
                                    this.findPage();
                                    this.ids=[];
                                    this.checkBoxData=[];
                                });
                            }).catch(() => {
                                this.$message({
                                    type: 'info',
                                    message: '放弃取消预约'
                                });
                            });
                        } else{
                            alert("请至少选择一条数据")
                        }

                    }
                },
                selectcheckBox(val) {
                    this.ids=[];
                    this.checkBoxData={};
                    this.checkBoxData = val;
                    for (var i = 0 , len = this.checkBoxData ; i < len.length; i++) {
                        this.ids.push(len[i]['id'])
                    }
                }

            }
        })
    </script>
</html>